﻿namespace Smart.ERP
{
    using Smart.Data.Helper;
    using Smart.Utils.Lib;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    public class CUSTOMER_GROUP
    {
        private bool m_Active;
        private string m_Customer_Group_ID;
        private string m_Customer_Group_Name;
        private string m_Description;

        public CUSTOMER_GROUP()
        {
            this.m_Customer_Group_ID = "";
            this.m_Customer_Group_Name = "";
            this.m_Description = "";
            this.m_Active = true;
        }

        public CUSTOMER_GROUP(string Customer_Group_ID, string Customer_Group_Name, string Description, bool Active)
        {
            this.m_Customer_Group_ID = Customer_Group_ID;
            this.m_Customer_Group_Name = Customer_Group_Name;
            this.m_Description = Description;
            this.m_Active = Active;
        }

        public void AddCombo(ComboBox combo)
        {
            MyLib.TableToComboBox(combo, this.GetList(), "CUSTOMER_GROUP_Name", "CUSTOMER_GROUP_ID");
        }

        public void AddComboAll(ComboBox combo)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            DataRow row = list.NewRow();
            row["CUSTOMER_GROUP_ID"] = "All";
            row["CUSTOMER_GROUP_Name"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            MyLib.TableToComboBox(combo, list, "CUSTOMER_GROUP_Name", "CUSTOMER_GROUP_ID");
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@Customer_Group_ID" };
            object[] myValues = new object[] { this.m_Customer_Group_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CUSTOMER_GROUP_Delete", myParams, myValues);
        }

        public string Delete(string Customer_Group_ID)
        {
            string[] myParams = new string[] { "@Customer_Group_ID" };
            object[] myValues = new object[] { Customer_Group_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CUSTOMER_GROUP_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string Customer_Group_ID)
        {
            string[] myParams = new string[] { "@Customer_Group_ID" };
            object[] myValues = new object[] { Customer_Group_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "CUSTOMER_GROUP_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string Customer_Group_ID)
        {
            string[] myParams = new string[] { "@Customer_Group_ID" };
            object[] myValues = new object[] { Customer_Group_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "CUSTOMER_GROUP_Delete", myParams, myValues);
        }

        public bool Exist(string Customer_Group_ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Customer_Group_ID" };
            object[] myValues = new object[] { Customer_Group_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("CUSTOMER_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string Customer_Group_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Customer_Group_ID" };
            object[] myValues = new object[] { Customer_Group_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("CUSTOMER_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Customer_Group_ID = Convert.ToString(reader["Customer_Group_ID"]);
                    this.m_Customer_Group_Name = Convert.ToString(reader["Customer_Group_Name"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string Customer_Group_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Customer_Group_ID" };
            object[] myValues = new object[] { Customer_Group_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "CUSTOMER_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Customer_Group_ID = Convert.ToString(reader["Customer_Group_ID"]);
                    this.m_Customer_Group_Name = Convert.ToString(reader["Customer_Group_Name"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string Customer_Group_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Customer_Group_ID" };
            object[] myValues = new object[] { Customer_Group_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "CUSTOMER_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Customer_Group_ID = Convert.ToString(reader["Customer_Group_ID"]);
                    this.m_Customer_Group_Name = Convert.ToString(reader["Customer_Group_Name"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetAll()
        {
            DataTable list = new DataTable();
            list = this.GetList();
            DataRow row = list.NewRow();
            row["CUSTOMER_GROUP_ID"] = "All";
            row["CUSTOMER_GROUP_Name"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            return list;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("CUSTOMER_GROUP_GetList");
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@Customer_Group_ID", "@Customer_Group_Name", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_Customer_Group_ID, this.m_Customer_Group_Name, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CUSTOMER_GROUP_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@Customer_Group_ID", "@Customer_Group_Name", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_Customer_Group_ID, this.m_Customer_Group_Name, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "CUSTOMER_GROUP_Insert", myParams, myValues);
        }

        public string Insert(string Customer_Group_ID, string Customer_Group_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Customer_Group_ID", "@Customer_Group_Name", "@Description", "@Active" };
            object[] myValues = new object[] { Customer_Group_ID, Customer_Group_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CUSTOMER_GROUP_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string Customer_Group_ID, string Customer_Group_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Customer_Group_ID", "@Customer_Group_Name", "@Description", "@Active" };
            object[] myValues = new object[] { Customer_Group_ID, Customer_Group_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "CUSTOMER_GROUP_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string Customer_Group_ID, string Customer_Group_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Customer_Group_ID", "@Customer_Group_Name", "@Description", "@Active" };
            object[] myValues = new object[] { Customer_Group_ID, Customer_Group_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "CUSTOMER_GROUP_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("CUSTOMER_GROUP", "CUSTOMER_GROUPID", "");
        }

        public string Update()
        {
            string[] myParams = new string[] { "@Customer_Group_ID", "@Customer_Group_Name", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_Customer_Group_ID, this.m_Customer_Group_Name, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CUSTOMER_GROUP_Update", myParams, myValues);
        }

        public string Update(string Customer_Group_ID, string Customer_Group_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Customer_Group_ID", "@Customer_Group_Name", "@Description", "@Active" };
            object[] myValues = new object[] { Customer_Group_ID, Customer_Group_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CUSTOMER_GROUP_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string Customer_Group_ID, string Customer_Group_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Customer_Group_ID", "@Customer_Group_Name", "@Description", "@Active" };
            object[] myValues = new object[] { Customer_Group_ID, Customer_Group_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "CUSTOMER_GROUP_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string Customer_Group_ID, string Customer_Group_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Customer_Group_ID", "@Customer_Group_Name", "@Description", "@Active" };
            object[] myValues = new object[] { Customer_Group_ID, Customer_Group_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "CUSTOMER_GROUP_Update", myParams, myValues);
        }

        public bool Active
        {
            get
            {
                return this.m_Active;
            }
            set
            {
                this.m_Active = value;
            }
        }

        public string Customer_Group_ID
        {
            get
            {
                return this.m_Customer_Group_ID;
            }
            set
            {
                this.m_Customer_Group_ID = value;
            }
        }

        public string Customer_Group_Name
        {
            get
            {
                return this.m_Customer_Group_Name;
            }
            set
            {
                this.m_Customer_Group_Name = value;
            }
        }

        public string Description
        {
            get
            {
                return this.m_Description;
            }
            set
            {
                this.m_Description = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class CUSTOMER_GROUP";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }
    }
}

